/* eslint-disable no-unused-vars */
import Mock from 'mockjs'
import Http from '@/lib/http'
const result = {
  success: true,
  desc: '',
  result: null,
}

function makeResult (result) {
  return {
    success: true,
    desc: '',
    result: result,
  }
}

const modulesFiles = require.context('./components', true, /\.js$/)
const modules = modulesFiles.keys().reduce((modules, modulePath) => {
  // set './app.js' => 'app'

  const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')

  const value = modulesFiles(modulePath)

  modules[moduleName] = value.default

  if (value.default) {
    value.default.forEach(item => {
      Mock.mock(
        new RegExp(Http.getUrl(item.url)),
        item.isAllResult ? item.result : makeResult(item.result),
      )
    })
  }
  return modules
}, {})

// import * as all from './components'

console.log('modules', modules)

/*

Mock.mock(
  new RegExp(Http.getUrl('/fullreduce/pageList')),
  makeResult({
    'total|10-500': 1,
    'list|10': [
      {
        'baseInfoId|+1': 132123211,
        'name|3-5': `😮`,
        startTime: () => Mock.mock('@datetime(T)'),
        endTime: () => Mock.mock('@datetime(T)') * 2,
        currentTime: () => Mock.mock('@datetime(T)'),
        'state|1-4': 1,
      }
    ]
  })
)

Mock.mock(
  new RegExp(Http.getUrl('/fullreduce/batchUpdateState')),
  makeResult(true)
)

Mock.mock(
  new RegExp(Http.getUrl('/fullreduce/batchDelete')),
  makeResult(true)
)

*/
